<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css"
          href="../../../js/jquery-easyui-1.9.5/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css"
          href="../../../js/jquery-easyui-1.9.5/themes/icon.css">
    <link rel="stylesheet" type="text/css"
          href="../../../js/jquery-easyui-1.9.5/themes/color.css">
    <script type="text/javascript"
            src="../../../js/jquery-easyui-1.9.5/jquery.min.js"></script>
    <script type="text/javascript"
            src="../../../js/jquery-easyui-1.9.5/jquery.easyui.min.js"></script>
</head>
<body>
<table id="volunteerJoinActivity_dg" title="活动参与信息" class="easyui-datagrid" style="width:100%;height:100%"
       url="../volunteerJoinActivity/list"
       toolbar="#volunteerJoinActivity_toolbar"
       rownumbers="true" pagination="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="vlistNo" style="width: 33%">参与编号</th>
        <th field="volunteerActivity" formatter="volunteerActivityFormatter" style="width: 25%">活动编号</th>
        <th field="volunteerMessage" formatter="volunteerMessageFormatter" style="width: 25%">义工编号</th>
    </tr>
    </thead>
</table>

<div id="volunteerJoinActivity_toolbar">
    <label for="searchVolunteerActivityVolunteerJoinActivity">活动编号:</label>
    <input id="searchVolunteerActivityVolunteerJoinActivity" name="volunteerActivity.activityNo"
           class="easyui-combobox" data-options="valueField:'activityNo',
           textField:'activityName',url:'../volunteerJoinActivity/volunteerActivityList'">
    <label for="searchVolunteerMessageVolunteerJoinActivity">义工编号:</label>
    <input id="searchVolunteerMessageVolunteerJoinActivity" name="volunteerMessage.volunteerNo"
           class="easyui-combobox" data-options="valueField:'volunteerNo',
           textField:'name',url:'../volunteerJoinActivity/volunteerMessageList'">
    <a id="searchButton" href="javascript:doVolunteerJoinActivitySearch();"
       class="easyui-linkbutton" data-options="iconCls:'icon-search'">Search</a>
    <a id="resetButton" href="javascript:doVolunteerJoinActivityReset();"
       class="easyui-linkbutton" data-options="iconCls:'icon-redo'">Reset</a>
    <br/>
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
       onclick="newVolunteerJoinActivity()">New VolunteerJoinActivity</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true"
       onclick="editVolunteerJoinActivity()">Edit VolunteerJoinActivity</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
       onclick="destroyVolunteerJoinActivity()">Remove VolunteerJoinActivity</a>
</div>

<%--        新增和修改对话框--%>
<div id="volunteerJoinActivity_dlg" class="easyui-dialog" style="width:400px;height:300px;padding:10px 20px"
     closed="true" buttons="#volunteerJoinActivity_dlg-buttons">
    <div class="ftitle" style="text-align: center">VolunteerJoinActivity Message</div>
    <br>
    <form id="volunteerJoinActivity_fm" method="post">
        <div class="fitem">
            <label for="volunteerActivity">活动编号&emsp;</label>
            <input id="volunteerActivity" name="volunteerActivity.activityNo" class="easyui-combobox"
                   prompt="volunteerActivity"
                   data-options="required:true,missingMessage:'volunteerActivity is not null',
                   valueField:'activityNo',textField:'activityName',url:'../volunteerJoinActivity/volunteerActivityList'"
                   style="width: 250px">
        </div>
        <br>
        <div class="fitem">
            <label for="volunteerMessage">义工编号&emsp;</label>
            <input id="volunteerMessage" name="volunteerMessage.volunteerNo" class="easyui-combobox"
                   prompt="volunteerMessage"
                   data-options="required:true,missingMessage:'volunteerMessage is not null',
                   valueField:'volunteerNo',textField:'name',url:'../volunteerJoinActivity/volunteerMessageList'"
                   style="width: 250px">
        </div>
    </form>
</div>
<div id="volunteerJoinActivity_dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok"
       onclick="saveVolunteerJoinActivity()">Save</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel"
       onclick="$('#volunteerJoinActivity_dlg').dialog('close')">Cancel</a>
</div>

<%--suppress JSJQueryEfficiency --%>
<script type="text/javascript">

    function volunteerActivityFormatter(value) {
        return value.activityName;
    }

    function volunteerMessageFormatter(value) {
        return value.name;
    }

    function doVolunteerJoinActivitySearch() {
        //调用datagrid对象的load方法查询数据，并传递查询参数
        $("#volunteerJoinActivity_dg").datagrid("load", {
            "volunteerActivity.activityNo": $("#searchVolunteerActivityVolunteerJoinActivity").val(),
            "volunteerMessage.volunteerNo": $("#searchVolunteerMessageVolunteerJoinActivity").val()
        });
    }

    function doVolunteerJoinActivityReset() {
        $("#searchVolunteerActivityVolunteerJoinActivity").combobox('clear');
        $("#searchVolunteerMessageVolunteerJoinActivity").combobox('clear');
        //清空查询参数后，重新加载数据
        $("#volunteerJoinActivity_dg").datagrid("load", {});
    }

    function loadVolunteerActivitySuccess(value) {
        $('#volunteerActivity').combobox({
            onLoadSuccess: function (data) {
                if (data) {
                    if (value) {
                        $('#volunteerActivity').combobox('select', value);
                    } else {
                        $('#volunteerActivity').combobox('select', data[0].activityNo);
                    }
                }
            }
        });
    }

    function loadVolunteerMessageSuccess(value) {
        $('#volunteerMessage').combobox({
            onLoadSuccess: function (data) {
                if (data) {
                    if (value) {
                        $('#volunteerMessage').combobox('select', value);
                    } else {
                        $('#volunteerMessage').combobox('select', data[0].volunteerNo);
                    }
                }
            }
        });
    }

    function newVolunteerJoinActivity() {
        $('#volunteerJoinActivity_dlg').dialog('open').dialog('setTitle', 'New VolunteerJoinActivity');
        $('#volunteerJoinActivity_fm').form('clear');
        url = '../volunteerJoinActivity/add';
        loadVolunteerActivitySuccess();
        loadVolunteerMessageSuccess();
    }

    function editVolunteerJoinActivity() {
        $('#volunteerJoinActivity_fm').form('clear');
        var row = $('#volunteerJoinActivity_dg').datagrid('getSelected');
        if (row) {
            $('#volunteerJoinActivity_dlg').dialog('open').dialog('setTitle', 'Edit VolunteerJoinActivity');
            $('#volunteerJoinActivity_fm').form('load', row);
            url = '../volunteerJoinActivity/edit?vlistNo=' + row.vlistNo;
            loadVolunteerActivitySuccess(row.volunteerActivity.activityNo);
            loadVolunteerMessageSuccess(row.volunteerMessage.volunteerNo);
        } else {
            $.messager.show({
                title: 'Error',
                msg: "请选择要修改的用户信息"
            });
        }
    }

    function destroyVolunteerJoinActivity() {
        var row = $('#volunteerJoinActivity_dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('Confirm', '是否需要删除该信息？', function (r) {
                if (r) {
                    $.post('../volunteerJoinActivity/delete', {vlistNo: row.vlistNo}, function (result) {
                        if (result.success) {
                            $('#volunteerJoinActivity_dg').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.show({
                title: 'Error',
                msg: "请选择要删除的用户信息"
            });
        }
    }

    function saveVolunteerJoinActivity() {
        $('#volunteerJoinActivity_fm').form('submit', {
            url: url,
            onSubmit: function () {
                // 提交表单前 表单验证
                return $(this).form('validate');
            },
            success: function (result) {
                // 收到服务器响应的json字符串后，调用这里的代码，回调函数当浏览器收到服务器返回的数据后才执行
                var result = eval('(' + result + ')');
                if (!result.success) {
                    $.messager.show({
                        title: 'Error',
                        msg: result.errorMsg
                    });
                } else {
                    $('#volunteerJoinActivity_dlg').dialog('close');		// 新增成功，关闭对话框
                    $('#volunteerJoinActivity_dg').datagrid('reload');	// 新增成功，刷新列表数据
                }
            }
        });
    }
</script>
</body>
</html>
